/**
 * Created by BaiYJ on 2017/4/21.
 */

// $(document).ready(function() {
//     $('#loginLogTable').DataTable();
// } );
var editor; // use a global for the submit and return data rendering
var table;
var userTypeId=0;

function getUrl(url,params) {
    for (var i=0;i<params.length;i++){
        if ($("#"+params[i]).val()!= "") {
            url = url + "&"+params[i]+"=" + $("#"+params[i]).val();
        }
    }
    return url;

}
$(document).ready(function () {
    $.ajax({
        url: '/commis/api/user/currentUser',
        type: "GET",
        async: false,
        dataType: 'json',
        data: {

        },
        success: function (response) {
            if (response.status==0) {
                console.log("用户存在");
                var user =response.data;
                userTypeId=user.userTypeId;
                console.log(userTypeId);
            } else if (response.status==1) {
                alert("登录用户已经过期，请重新登录");
                window.parent.location.href = "../../login.html";
            }
        },error: function (msg) {
            alert("登录用户已经过期，请重新登录");
            window.parent.location.href = "../../login.html";
        }
    })
    $.ajax({
        url: '/commis/api/user/all',
        async: false,
        dataType: 'json',
        success: function (response) {
            console.log(response.length);
            console.log(response);
            for (var i = 0; i < response.length; i++) {
                $("#userId").append("<option value='" + response[i].userId + "'>" + response[i].userName + "</option>");
            }


        }, error: function () {

        }
    });

    $('#loginTime').datetimepicker({
        language: 'zh-CN',
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true,
        todayBtn: true,


    });


 



    table = $('#dataTable').DataTable({

        ajax: "/commis/api/loginLog/pageDatatables",
        autoWidth:true,
        responsive: true,
        pageLength: 10,


        serverSide: true,
        processing: true,
        lengthChange: false,//是否允许用户改变表格每页显示的记录数
        ordering: false,//是否允许用户排序
        paging: true,//是否分页
        pagingType: "full_numbers",//除首页、上一页、下一页、末页四个按钮还有页数按钮
        searching: false,//是否开始本地搜索
        stateSave: false,//刷新时是否保存状态
        autoWidth: true,//自动计算宽度
        language: {
            emptyTable: "没有数据",
            search: "搜索:",
            paginate: {
                first: "首页",
                previous: "上一页",
                next: "下一页",
                last: "尾页"

            },
            lengthMenu: "每页 _MENU_ 条记录",
            zeroRecords: "没有找到记录",
            info: "第 _PAGE_ 页 ( 总共 _PAGES_ 页 )，共 _TOTAL_ 项",
            infoEmpty: "无记录",
            infoFiltered: "(从 _MAX_ 条记录过滤)"
        },
        columns: [
            {
                data: 'user.userName', defaultContent: ""
            },
            {
                data: 'loginTime', defaultContent: ""
            }]

    });


    $('#search').on('click', function () {

        var url = "/commis/api/loginLog/pageDatatables?1=1"
        var params=["userId","loginTime"];
        url=getUrl(url,params);
        table.ajax.url(url).load();
    });




})

//设置框架
$(function () {
    $("#page_style").frame({
        float: 'left',
        menu_nav: '.Quick_operation',
        color_btn: '.skin_select',
        Sellerber_menu: '.list_content',
        Sellerber_header: '.Sellerber_header',
    });
});
$("#iframe_box").niceScroll({
    cursorcolor: "#888888",
    cursoropacitymax: 1,
    touchbehavior: false,
    cursorwidth: "5px",
    cursorborder: "0",
    cursorborderradius: "5px"
});
/*********************/
require.config({
    paths: {
        echarts: './js/dist'
    }
});